﻿
    using System;
    using System.Data;
    using System.Web.UI;
    using Utils;

    public partial class WebPage_UserControls_dingdansearch : UserControl
    {
        private string express = string.Empty;
        protected string request_content = string.Empty;
        protected int request_date = -1;
        protected string request_endTime = string.Empty;
        protected int request_express = 0;
        protected string request_firstTime = string.Empty;
        protected int request_selecttype = -1;
        protected int request_time = -1;
        private bool searchexpress = false;
        private string url = string.Empty;

        public string GetUrl()
        {
            return this.url;
        }

        public string GetWhereString()
        {
            int @int = Helper.GetInt(base.Request["key"], 1);
            this.url = this.url + "&key=" + @int;
            string str = string.Empty;
            if (base.Request.HttpMethod == "POST")
            {
                this.request_time = Helper.GetInt(base.Request.Form["time"], -1);
                this.request_selecttype = Helper.GetInt(base.Request.Form["selecttype"], -1);
                this.request_date = Helper.GetInt(base.Request.Form["date"], -1);
                this.request_firstTime = Helper.GetString(base.Request.Form["firstTime"], string.Empty);
                this.request_endTime = Helper.GetString(base.Request.Form["endTime"], string.Empty);
                this.request_content = Helper.GetString(base.Request.Form["searchcontent"], string.Empty);
                if (this.SearchExpress)
                {
                    this.request_express = Helper.GetInt(base.Request.Form["express"], 0);
                }
            }
            else
            {
                this.request_time = Helper.GetInt(base.Request.QueryString["time"], -1);
                this.request_selecttype = Helper.GetInt(base.Request.QueryString["selecttype"], -1);
                this.request_date = Helper.GetInt(base.Request.QueryString["date"], -1);
                this.request_firstTime = Helper.GetString(base.Request.QueryString["firstTime"], string.Empty);
                this.request_endTime = Helper.GetString(base.Request.QueryString["endTime"], string.Empty);
                this.request_content = Helper.GetString(base.Request.QueryString["searchcontent"], string.Empty);
                if (this.SearchExpress)
                {
                    this.request_express = Helper.GetInt(base.Request.QueryString["express"], 0);
                }
            }
            if (this.request_date == 1)
            {
                this.url = this.url + "&date=1";
                if (Helper.GetDateTime(this.request_firstTime, DateTime.MinValue) != DateTime.MinValue)
                {
                    if ((this.request_time > -1) && (this.request_time < 0x18))
                    {
                        this.url = string.Concat(new object[] { this.url, "&firstTime=", this.request_firstTime, "&time=", this.request_time });
                        str = str + " and order_create_time>='" + Helper.GetDateTime(this.request_firstTime, DateTime.Now).ToString("yyyy-MM-dd " + this.request_time + ":0:0") + "'";
                    }
                    else
                    {
                        this.url = this.url + "&firstTime=" + this.request_firstTime;
                        str = str + " and order_create_time>='" + Helper.GetDateTime(this.request_firstTime, DateTime.Now).ToString("yyyy-MM-dd 0:0:0") + "'";
                    }
                }
                if (Helper.GetDateTime(this.request_endTime, DateTime.MinValue) != DateTime.MinValue)
                {
                    if ((this.request_time > -1) && (this.request_time < 0x18))
                    {
                        this.url = this.url + "&endTime=" + this.request_endTime;
                        str = str + " and order_create_time<='" + Helper.GetDateTime(this.request_endTime, DateTime.Now).ToString("yyyy-MM-dd " + this.request_time + ":59:59") + "'";
                    }
                    else
                    {
                        this.url = this.url + "&endTime=" + this.request_endTime;
                        str = str + " and order_create_time<='" + Helper.GetDateTime(this.request_endTime, DateTime.Now).ToString("yyyy-MM-dd 23:59:59") + "'";
                    }
                }
            }
            if (this.request_date == 2)
            {
                this.url = this.url + "&date=2";
                if (Helper.GetDateTime(this.request_firstTime, DateTime.MinValue) != DateTime.MinValue)
                {
                    if ((this.request_time > -1) && (this.request_time < 0x18))
                    {
                        this.url = string.Concat(new object[] { this.url, "&firstTime=", this.request_firstTime, "&time=", this.request_time });
                        str = str + " and pay_time>='" + Helper.GetDateTime(this.request_endTime, DateTime.Now).ToString("yyyy-MM-dd " + this.request_time + ":0:0") + "'";
                    }
                    else
                    {
                        this.url = this.url + "&firstTime=" + this.request_firstTime;
                        str = str + " and pay_time>='" + Helper.GetDateTime(this.request_endTime, DateTime.Now).ToString("yyyy-MM-dd 0:0:0") + "'";
                    }
                }
                if (Helper.GetDateTime(this.request_endTime, DateTime.MinValue) != DateTime.MinValue)
                {
                    if ((this.request_time > -1) && (this.request_time < 0x18))
                    {
                        this.url = this.url + "&endTime=" + this.request_endTime;
                        str = str + " and pay_time<='" + Helper.GetDateTime(this.request_endTime, DateTime.Now).ToString("yyyy-MM-dd " + this.request_time + ":59:59") + "'";
                    }
                    else
                    {
                        this.url = this.url + "&endTime=" + this.request_endTime;
                        str = str + " and pay_time<='" + Helper.GetDateTime(this.request_endTime, DateTime.Now).ToString("yyyy-MM-dd 23:59:59") + "'";
                    }
                }
            }
            if (this.request_content.Length > 0)
            {
                switch (this.request_selecttype)
                {
                    case 1:
                        str = str + " and user_id in(select id from [user] where Username like '" + this.request_content + "%')";
                        break;

                    case 2:
                        str = str + " and user_id in(select id from [user] where email like '" + this.request_content + "%')";
                        break;

                    case 3:
                        str = str + " and order_id=" + Helper.GetInt(this.request_content, 0);
                        break;

                    case 4:
                        str = string.Concat(new object[] { str, " and (team_id=", Helper.GetInt(this.request_content, 0), " or order_id in(select order_id from orderdetail where teamid=", Helper.GetInt(this.request_content, 0), "))" });
                        break;

                    case 5:
                        {
                            string[] strArray = this.request_content.Split(new string[] { "as" }, StringSplitOptions.RemoveEmptyEntries);
                            if (strArray.Length >= 3)
                            {
                                str = str + " and pay_id like '" + strArray[0] + "as" + strArray[1] + "as" + strArray[2] + "as%'";
                            }
                            break;
                        }
                    case 6:
                        str = str + " and Express_no='" + this.request_content + "'";
                        break;

                    case 7:
                        str = str + " and order_mobile like '" + this.request_content + "%'";
                        break;
                }
                this.url = this.url + "&selecttype=" + this.request_selecttype;
                this.url = this.url + "&searchcontent=" + base.Server.UrlEncode(this.request_content);
            }
            if (this.SearchExpress)
            {
                this.express = string.Empty;
                this.url = this.url + "&express=" + this.request_express;
                DataTable table = new DataTable();
                using (ASDhtDataBase base2 = new ASDhtDataBase(false))
                {
                    table = base2.SqlExecDatatable("select t.Id,t.Name,COUNT(*) as num from (select id,name from Category where zone='express')t left join [Order] on(t.Id=[Order].Express_id) where [Order].State='pay' and express='Y' and [Order].Express_id>0 and isnull([Order].Express_xx,'')<>'已打印' group by t.Id,t.Name");
                }
                this.express = this.express + "<option value='0'></option>";
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    DataRowObject obj2 = new DataRowObject(table.Rows[i]);
                    if (obj2.ToInt("id") == this.request_express)
                    {
                        this.express = this.express + "<option selected value='" + obj2["id"] + "'>" + obj2["name"] + "(" + obj2["num"] + ")</option>";
                    }
                    else
                    {
                        this.express = this.express + "<option value='" + obj2["id"] + "'>" + obj2["name"] + "(" + obj2["num"] + ")</option>";
                    }
                }
                if (this.request_express > 0)
                {
                    str = str + " and express_id=" + this.request_express;
                }
            }
            this.url = this.url + "&page={0}";
            this.url = "?" + this.url.Substring(1);
            if (base.Request.Url.Query.Length > 0)
            {
                this.url = base.Request.Url.AbsoluteUri.Replace(base.Request.Url.Query, "") + this.url;
            }
            else
            {
                this.url = base.Request.Url.AbsoluteUri + this.url;
            }
            return (" 1=1 " + str);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public string Express
        {
            get
            {
                if (this.express == string.Empty)
                {
                    DataTable table = new DataTable();
                    using (ASDhtDataBase base2 = new ASDhtDataBase(false))
                    {
                        table = base2.SqlExecDatatable("select t.Id,t.Name,COUNT(*) as num from (select id,name from Category where zone='express')t left join [Order] on(t.Id=[Order].Express_id) where [Order].State='pay' and express='Y' and [Order].Express_id>0 and isnull([Order].Express_xx,'')<>'已打印' group by t.Id,t.Name");
                    }
                    this.express = this.express + "<option value='0'></option>";
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        DataRowObject obj2 = new DataRowObject(table.Rows[i]);
                        this.express = this.express + "<option value='" + obj2["id"] + "'>" + obj2["name"] + "(" + obj2["num"] + ")</option>";
                    }
                }
                return this.express;
            }
        }

        public bool SearchExpress
        {
            get
            {
                return this.searchexpress;
            }
            set
            {
                this.searchexpress = value;
            }
        }
    }


